function [schedTrn, schedPos, schedFB, nTrial] = setSched(subjID, grp, session, dirLog)

% schedTrn        = [1 1 1, 2 2 2, 3 3 3, 4 4 4];
% schedPos        = [0 90 120, 90 120 0, 120 0 90, 0 120 90]*pi/180;

fname = sprintf('%s/S%s-G%02d.mat', dirLog, subjID, grp);
if exist(fname, 'file')
    load(fname);
else
    [schedTrnD1B, schedPosD1B, schedFBD1B, nTrialD1B, ...
     schedTrnD2P, schedPosD2P, schedFBD2P, nTrialD2P, ...
     schedTrnD2T, schedPosD2T, schedFBD2T, nTrialD2T, ...
     schedTrnD3T, schedPosD3T, schedFBD3T, nTrialD3T] = genSched(grp);
 
    save(fname, 'schedTrnD1B', 'schedPosD1B', 'schedFBD1B', 'nTrialD1B', ...
                'schedTrnD2P', 'schedPosD2P', 'schedFBD2P', 'nTrialD2P', ...
                'schedTrnD2T', 'schedPosD2T', 'schedFBD2T', 'nTrialD2T', ...
                'schedTrnD3T', 'schedPosD3T', 'schedFBD3T', 'nTrialD3T');
end

switch session
    case 1
        % Day 1 baseline session
        schedTrn = schedTrnD1B;
        schedPos = schedPosD1B;
        schedFB  = schedFBD1B;
        nTrial = nTrialD1B;
    case 2
        % Day 2 practice session
        schedTrn = schedTrnD2P;
        schedPos = schedPosD2P;
        schedFB  = schedFBD2P;
        nTrial = nTrialD2P;
    case 3
        % Day 2 test session: generalization for group 1~3, retention
        % for group 4~9
        schedTrn = schedTrnD2T;
        schedPos = schedPosD2T;
        schedFB  = schedFBD2T;
        nTrial = nTrialD2T;
    case 4
        % Day 3 test session: retention test only for group 4~9
        schedTrn = schedTrnD3T;
        schedPos = schedPosD3T;
        schedFB  = schedFBD3T;
        nTrial = nTrialD3T;
end

return;